<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1 style="color: red;">注册页面</h1>
  <!-- <img src="./img/1.png"> -->

  <input type="text" class="username">
  <input type="text" class="password">
  <button class="btn">提交</button>

  <script src="./js/axios.js"></script>
  <script>

    const username = document.querySelector('.username');
    const password = document.querySelector('.password');
    const btn = document.querySelector('.btn');
    btn.onclick = () => {
      axios.post('/api/register', {
        name: username.value.trim(),
        pwd: password.value.trim()
      }).then(res => {
        console.log(res, 'res')
        if (res.data.errno === -1) {
          alert(res.data.msg)
        } else {
          alert('注册成功，跳转登陆')
          window.location.href = 'login.html'
        }
      })
      // axios.get('/api/register', {
      //   params: {
      //     name: username.value.trim(),
      //     pwd: password.value.trim()
      //   }
      // }).then(res => {
      //   console.log(res, 'res')
      //   if (res.data.errno === -1) {
      //     alert(res.data.msg)
      //   } else {
      //     alert('注册成功，跳转登陆')
      //     window.location.href = 'login.html'
      //   }
      // })
    }

  </script>

</body>

</html>